/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
    Text, LineColumn, InputLine, SuffixInput, Table, TableBody, TableRow, CCell, TableHead, useTheme,
} from "customize-easy-ui-component";
import {CCellUnit, InspectRecordLayout, InternalItemProps, RepLink, SelectHookfork, useItemInputControl,} from "../../common/base";
import {useMeasureInpFilter} from "../../common/hooks";
import {resTranslCheck} from "../../common/helper";

const 内容方法=[ ['平晃峰','A95峰峰值', <>≤15cm/s<sup>2</sup></>,
                '检测时轿厢空载，以正常速度上、下全行程运行各1次，采用电梯综合质量分析仪进行定量检测。取两次运行中各自最大的数据',<>cm/s<sup>2</sup></>],
    ['平晃最','最大峰峰值',<>≤20cm/s<sup>2</sup></>, null, <>cm/s<sup>2</sup></>],
    ['垂抖峰','A95峰峰值',<>≤20cm/s<sup>2</sup></>, null, <>cm/s<sup>2</sup></>],
    ['垂抖最','最大峰峰值',<>≤30cm/s<sup>2</sup></>, null, <>cm/s<sup>2</sup></>],
    ['机房噪','机房噪声', 'v≤2.5m/s时，应≤80dB(A)；2.5m/s＜v≤6.0m/s，应≤85dB(A)；v＞6.0m/ s，不超过制造单位的允许值。制造单位未规定的，按照额定速度为6.0m/s的电梯限值指标判定',
         '电梯以额定速度运行，声音测量传感器置于距地面高1.5m、 驱动主机1.0m处测试，测试点不少于3点，取平均值', 'dB(A)'],
    ['厢内噪','轿厢内噪声', 'V≤2.5m/s的电梯应≤55dB(A)，2.5m/ s<V≤6.0m/s的电梯应≤60dB(A)',
                  '轿厢空载以正常速度上、下运行，检验人员在轿厢内用声级计测量轿厢噪声。取最大值', 'dB(A)'],
    ['关门噪','开关门噪声', '≤65dB(A)',
        '采用声级计在行程上、中、下部各抽查一处测量开关门过程中最大的噪声。取最大值', 'dB(A)'],
    ['无机门噪','无机房电梯层门处噪声', 'v≤2.5m/s时，应≤65dB(A)；v＞2.5m/s不超过制造单位的允许值。制造单位未规定的，按照额定速度为2.5m/s的电梯限值指标判定',
        '声音测量传感器置于驱动主机安装位置最近层站开门宽度的中部对着层门，在水平方向距门扇0.5m, 垂直方向距层站地面1.5m 处测试，取出发端站门关闭后至到达端站门开启前，电梯全程上、下运行过程中以额定速度运行时的最大值', 'dB(A)'],
];
export const itemA运行质: string[] = [];
内容方法.forEach(([name, ]:any, i:number)=> {
    const names=[name,  name +'r'];
    itemA运行质.push( ...names );
});
export const OperationQuality =
    React.forwardRef(({children, show, alone = true, refWidth, label}: InternalItemProps, ref
    ) => {
        const [getInpFilter]=useMeasureInpFilter(null, itemA运行质, );
        const {inp, setInp} = useItemInputControl({ ref });
        return (
            <InspectRecordLayout inp={inp} setInp={setInp}  getInpFilter={getInpFilter} show={show}
                                 alone={alone}  label={'附录C 电梯运行质量检测记录表'}>
                <Text variant="h5">{label}</Text>
                <Text>项目检测方法:</Text>
                <div css={{marginLeft: '1rem'}}>
                    序号1-4，轿厢水平晃动 和 轿厢垂直抖动 ：<br/>
                    {内容方法[0][3]}。<br/>
                    {(new Array(4)).fill(null).map(( _,  w:number) => {
                        const [_n, title,_r,desc,_u]=内容方法[w+4];
                        return <div key={w}>序号{w+5}，噪声 - {title}：<br/>{desc}。</div>;
                    })}
                </div>
                <hr/>
                {内容方法.map(( _,  w:number) => {
                    const [name,title,require,desc,unit]=内容方法[w] as any;
                    const pref= w<2? '轿厢水平晃动': w>3? '噪声' : '轿厢垂直抖动';
                    return <div key={w}>
                        {w+1}项目: {pref} 》 {title}：检测要求 {require}
                        <LineColumn>
                            <InputLine label={`${w+1}项目:${title}-实测值`}>
                                <SuffixInput  value={inp?.[name] ||''}
                                              onSave={txt=> setInp({...inp,[name]: txt || undefined })}>{unit}</SuffixInput>
                            </InputLine>
                            <InputLine label={`${w+1}项目:${title}-检测结果`}>
                                <SelectHookfork value={ inp?.[name+'r'] ||''}
                                                onChange={e => setInp({ ...inp, [name+'r']: e.currentTarget.value||undefined}) }/>
                            </InputLine>
                        </LineColumn>
                    </div>;
                })}
            </InspectRecordLayout>
        );
} );

export const OperationQualityVw= ({children, orc, rep,label } : { orc: any, rep: any,label:any, children?: any}
) => {
    // const theme = useTheme();
    return <>
        <div css={{"@media print": {paddingBottom: '8rem', pageBreakInside: 'avoid'}}}>
            <Text variant="h4" css={{marginTop: '1rem',
            }}>{label}</Text>
        </div>
        <Table id={'OperationQuality'} fixed={ ["2.8%","7%","10.4%","26%","%","11%","8.1%"]  }
               css={ {borderCollapse: 'collapse', "@media print": {marginTop: '-8rem'}} }  tight  miniw={800}>
            <TableHead>
                <TableRow>
                    <CCell><Text css={{fontSize:'0.7rem'}}>序号</Text></CCell><CCell>项目</CCell><CCell>检测内容</CCell><CCell>检测要求</CCell><CCell>检测方法</CCell><CCell>实测值</CCell><CCell>检测结果</CCell>
                </TableRow>
            </TableHead>
            <TableBody>
                <RepLink ori rep={rep} tag={'OperationQuality'}>
                    {内容方法.map(( _,  w:number) => {
                        const [name,title,require,desc,unit]=内容方法[w] as any;
                        const pref= w<2? '轿厢水平晃动': w>3? '噪声' : '轿厢垂直抖动';
                        return <TableRow key={w}>
                            <CCell>{w+1}</CCell>
                            {0===w? <CCell rowSpan={2}>轿厢水平晃动</CCell> :
                                2===w? <CCell rowSpan={2}>轿厢垂直抖动</CCell> :
                                    4===w? <CCell rowSpan={4} split>噪声</CCell> : null
                            }
                            <CCell>{title}</CCell>
                            <CCell>{require}</CCell>
                            {w<4? (0===w&&<CCell rowSpan={4} split>{desc}</CCell>)  : <CCell>{desc}</CCell>}
                            <CCellUnit unit={unit}>{orc?.[name]}</CCellUnit>
                            <CCell>{resTranslCheck(orc?.[name+'r'])}</CCell>
                        </TableRow>
                    })}
                </RepLink>
            </TableBody>
        </Table>
    </>;
};

/*CCUnit原本的:
            <TableRow>
                <CCell>4</CCell>
                <CCell>最大峰峰值</CCell>
                <CCell>≤30cm/s<sup>2</sup></CCell>
                <CCell><div css={{ display: 'flex',justifyContent: 'space-around',alignItems: 'center'}}>
                    <Text >{orc.垂抖最}</Text>
                    <Text css={{ [theme.mediaQueries.lg+', print']: {wordBreak: 'keep-all'} }}>
                        cm/s<sup>2</sup></Text>
                </div></CCell>
                <CCell>{resTranslCheck(orc?.垂抖最r)}</CCell>
            </TableRow>
* */